package com.training;

import java.io.*;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author daks1653
 */
public class FilesSample {


    public static void main(String[] args) throws IOException, ClassNotFoundException
	{
		try {
			ObjectOutputStream out =
				  new ObjectOutputStream (
				    new FileOutputStream("D:\\javae\\Employee.txt"));

            Employee eObj = new Employee(100,"ramesh",4500);
            out.writeObject(eObj);
            Employee eObj1 = new Employee(101,"chendhil",4500);
            out.writeObject(eObj1);
            Employee eObj2 = new Employee(102,"govind",4500);
            out.writeObject(eObj2);
            Employee eObj3 = new Employee(103,"mohan",5400);
            out.writeObject(eObj3);

            ObjectInputStream inObj=new ObjectInputStream(
               new FileInputStream("D:\\javae\\Employee.txt"));

                  eObj = (Employee) inObj.readObject();

                  System.out.println(eObj.getEmpId());

            System.out.println("Object Serialized in File");


            BufferedReader in = new BufferedReader(new FileReader("D:\\javae\\Employee.txt"));
            
            while(in.readLine()!=null) {
                in.readLine();
                    System.out.println(eObj.getEmpId());
                    System.out.println(eObj.getEmpName());
                    System.out.println(eObj.getEmpSal());
            }
           
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }

}
